package de.lm.android.jogging;

public class StopWatch {

	private long startTime = 0;
	private long stopTime = 0;
	private boolean running = false;

	public void start() {
		this.startTime = System.currentTimeMillis();
		this.running = true;
	}

	public void stop() {
		this.stopTime = System.currentTimeMillis();
		this.running = false;
	}

	// vergangene Zeit in Millisekunden
	public long getElapsedTime() {
		long elapsed;
		if (running) {
			elapsed = (System.currentTimeMillis() - startTime);
		} else {
			elapsed = (stopTime - startTime);
		}
		return elapsed;
	}

	// vergangene Zeit in Sekunden
	public long getElapsedTimeSecs() {
		long elapsed, help = 0, helpmin = 0;
		if (running) {
			elapsed = ((System.currentTimeMillis() - startTime) / 1000);
		} else {
			elapsed = ((stopTime - startTime) / 1000);
		}
		if (elapsed >= 100) {
			help = elapsed;
			helpmin = elapsed;
			help = (help * 100) / 60;
			helpmin = (helpmin / 60) * 100;
			help = help - helpmin;
			elapsed = help * 60;
			elapsed = elapsed / 100;
			return elapsed;
		} else if (elapsed >= 60) {
			elapsed = elapsed - 60;
			return elapsed;
		} else {
			return elapsed;
		}
	}

	public long getElapsedTimeMins() {
		long elapsed;
		if (running) {
			elapsed = ((System.currentTimeMillis() - startTime) / 60000);
		} else {
			elapsed = ((stopTime - startTime) / 60000);
		}
		return elapsed;
	}
}